/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.projet.facades;

import com.projet.entities.Commande;
import com.projet.entities.Utilisateur;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Oussama
 */
@Stateless
public class CommandeFacade extends AbstractFacade<Commande> {
    @PersistenceContext(unitName = "ProjetPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CommandeFacade() {
        super(Commande.class);
    }
     public List<Commande> joincommande(String MotDePasse) {
       //getEntityManager().createNamedQuery("Utilisateur.findByName").setParameter("name", UserName).getResultList().get(0);
        try{
            List<Commande> commande = (List<Commande>) getEntityManager().createNamedQuery("Commande.findByMotDePasse").setParameter("MotDePasse", MotDePasse).getResultList();
            return commande;
        }catch(NoResultException e){
            return null;
        }catch(NonUniqueResultException e){
            return null;
        } 
    }
    
}
